﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace DXBase.Structs
{
	/// <summary>
	/// This struct provides a convenient way to convert an Uint32 to an array 4 Bytes
	/// </summary>
	[StructLayout(LayoutKind.Explicit)]
	public struct Byte4
	{
		[FieldOffset(0)]
		public uint UINT32;

		[FieldOffset(0)]
		public byte Byte0;
		[FieldOffset(1)]
		public byte Byte1;
		[FieldOffset(2)]
		public byte Byte2;
		[FieldOffset(3)]
		public byte Byte3;

		public byte this[int index]
		{
			get
			{
				switch (index)
				{
					case 0: return Byte0;
					case 1: return Byte1;
					case 2: return Byte2;
					case 3: return Byte3;
					default:
						throw new ArgumentOutOfRangeException();
				}
			}
			set
			{
				switch (index)
				{
					case 0:
						Byte0 = value;
						break;
					case 1:
						Byte1 = value;
						break;
					case 2:
						Byte2 = value;
						break;
					case 3:
						Byte3 = value;
						break;
					default:
						throw new ArgumentOutOfRangeException();
				}
			}
		}
	}

	/// <summary>
	/// This struct provides a convenient way to convert an Uint32 to an array 4 SBytes
	/// </summary>
	[StructLayout(LayoutKind.Explicit)]
	public struct SByte4
	{
		[FieldOffset(0)]
		public uint UINT32;

		[FieldOffset(0)]
		public sbyte SByte0;
		[FieldOffset(1)]
		public sbyte SByte1;
		[FieldOffset(2)]
		public sbyte SByte2;
		[FieldOffset(3)]
		public sbyte SByte3;

		public sbyte this[int index]
		{
			get
			{
				switch (index)
				{
					case 0: return SByte0;
					case 1: return SByte1;
					case 2: return SByte2;
					case 3: return SByte3;
					default:
						throw new ArgumentOutOfRangeException();
				}
			}
			set
			{
				switch (index)
				{
					case 0:
						SByte0 = value;
						break;
					case 1:
						SByte1 = value;
						break;
					case 2:
						SByte2 = value;
						break;
					case 3:
						SByte3 = value;
						break;
					default:
						throw new ArgumentOutOfRangeException();
				}
			}
		}
	}
}
